<{include file="header.html"}>

<script type="text/javascript">

	function validate()
	{
		var name = document.getElementById('NAME');
		var image = document.getElementById('IMAGE');

		// checking NAME
		if(isEmptyTextBox(name, '<{$smarty.const._MSG_NAME_IS_EMPTY|utf8_escape_js}>'))
			return false;

		if(!isValidLengthTextBox(name, <{$smarty.const.MAX_LENGTH_NAME}>, '<{$smarty.const._MSG_NAME_IS_TOO_LONG|utf8_escape_js}>')){
            return false;
        }

		// validate IMAGE
		// - IMAGE must be not empty
		// - the extension must is 'png','jpg','jpeg','gif', or 'bmp'
		<{if $banner->ID}>
		if ($('#IMAGE').val() != '' && !validateExtension($('#IMAGE').val(), new Array('png','jpg','jpeg','gif','bmp'))) {
			showErrorBubble($('#IMAGE'), '<{$smarty.const._MSG_IMAGE_EXTENSION_IS_INVALID|utf8_escape_js}>');
			return false;
		}
		<{else}>
		if(isEmptyTextBox(image, '<{$smarty.const._MSG_IMAGE_IS_EMPTY|utf8_escape_js}>')) {
			return false;
		}
		if (!$('#IMAGE').val() || $('#IMAGE').val() == '' || !validateExtension($('#IMAGE').val(), new Array('png','jpg','jpeg','gif','bmp'))) {
			showErrorBubble($('#IMAGE'), '<{$smarty.const._MSG_IMAGE_EXTENSION_IS_INVALID|utf8_escape_js}>111');
			return false;
		}
		<{/if}>

		document.edit_form.submit();
	}

	function validateExtension(fileName, extension)
	{
		var fileExtension = getFileExtension(fileName).toLowerCase();
		if ($.isArray(extension)) {
			for(var i = 0; i < extension.length; i++) {
				if (fileExtension == extension[i].toLowerCase()) {
					return true;
				}
			}
		} else {
			return (fileExtension == extension.toLowerCase());
		}

		return false;
	}

	function getFileExtension(fileName)
	{
		var found = fileName.lastIndexOf('.') + 1;
		return (found > 0 ? fileName.substr(found) : "");
	}

</script>

		<div class="box_two_third">
			<div class="box_head"><{$smarty.const._LB_BANNER_MANAGEMENT|utf8_escape_html}></div>
			<div class="box_content">

				<form enctype="multipart/form-data" action="<{$smarty.server.REQUEST_URI}>" method="post" name="edit_form">
				<input type="hidden" id="ID" value="<{$banner->ID}>"/>
				<input type="hidden" id="act" name="act" value="<{$smarty.const.ACT_VALID_EDIT}>"/>
				<table>
                    <tr>
						<td ><{$smarty.const._LB_NAME|utf8_escape_html}>&nbsp;:&nbsp;<{$smarty.const._LB_REQUIRE_FIELD}></td>
						<td colspan="3"><input name="NAME" id="NAME" type="text" class="long_input" value="<{$banner->NAME|utf8_escape_html}>" /></td>
					</tr>
                    <tr>
						<td ><{$smarty.const._LB_DISABLED|utf8_escape_html}>&nbsp;:&nbsp;</td>
						<td colspan="3" style="padding-left:2px;"><input type="checkbox" value="1" name="DISABLED" <{if $banner->DISABLED}>checked<{/if}>/></td>
					</tr>
					<tr>
						<td><{$smarty.const._LB_IMAGE|utf8_escape_html}>&nbsp;:&nbsp;<{$smarty.const._LB_REQUIRE_FIELD}></td>
						<td>
							<{if $banner->IMAGE}>
								<img style="display: block; opacity: 1; cursor: pointer;" src="<{$smarty.const.IMAGE_URL}>/thumb<{$banner->IMAGE}>">
								<br/>
							<{/if}>
							<input type="file" name="IMAGE" id="IMAGE" size="60" >
                            <br />(The image size should be at 1000x150)
						</td>
					</tr>
                    
					<tr>
						<td ><{$smarty.const._LB_MODULES|utf8_escape_html}>&nbsp;:&nbsp;</td>
						<td colspan="3">
							<table>
							<{while $module->fetch()}>
								<tr>
									<td width="1%"><input type="checkbox" value="<{$module->ID}>" name="ID_MODULE[]" <{if in_array($module->ID, $arr_modules)}>checked<{/if}>/></td>
									<td><{$module->NAME|utf8_escape_html}></td>
								</tr>
							<{/while}>
							</table>
						</td>						
					</tr>
					<tr>
						  <td class="submit" colspan="4" style="padding-top:10px"><br />
								<a class="tribullet" href="<{$backlink}>"><{$smarty.const._LB_BACK}></a>
								<a class="tribullet" href="#" onclick="validate()"><{$smarty.const._LB_VALIDATE}></a>
							</td>
						</tr>

				</table>
				</form>

			</div>
		</div>
<{include file="footer.html"}>
